#include <stdio.h>

typedef unsigned char *byte_ponter;

/**
 * 2.4 对象的字节表示
 */
int main()
{
    test_show_bytes(1);

    int val = 0x87654321;
    byte_ponter valp = (byte_ponter) &val;
    show_bytes(valp,1);
    show_bytes(valp,2);
    show_bytes(valp,3);

    const char *s = "abcdef";
    show_bytes((byte_ponter) s,strlen(s));
    return 0;
}

void show_bytes(byte_ponter start, size_t len) 
{
    size_t i;
    for ( i = 0; i < len; i++)
    {
        printf(" %.2x", start[i]);
    }
    printf("\n");
}

void show_int(int x)
{
    show_bytes((byte_ponter) &x, sizeof(int));
}

void show_float(int x)
{
    show_bytes((byte_ponter) &x, sizeof(float));
}

void show_pointer(void *x)
{
    show_bytes((byte_ponter) &x, sizeof(void *));
}

void test_show_bytes(int val){
    int ival = val;
    float fval = (float) ival;
    int *pval = &ival;
    show_int(ival);
    show_float(fval);
    show_pointer(pval);
}

